﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics.Contracts;

namespace ImapX.Parsing.Tokens
{
    public class Number : Token
    {
        internal Number(bool canBeNIL = true) : base(canBeNIL) { }

        protected override string BeginPattern
        {
            get { return @"\d+"; }
        }

        protected override string ParseBegin(string input)
        {
            var match = Match(input, BeginPattern);

            if (!match.Success) throw new ImapException("Failed to parse fetched number");

            Value = Convert.ToInt32(match.Value);

            input = input.Substring(match.Length);

            return input;
        }

        public int Value { get; set; }
    }
}
